package com.happy016.framework;



import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.SimpleMappingExceptionResolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;



/**
 * 异常控制handler
 * create on 2016/9/2 11:54
 * @author linyb
 */
public class MyExceptionHandler extends  SimpleMappingExceptionResolver {


    //@Autowired
    //private IExceptionService exceptionService;

    public ModelAndView doResolveException(HttpServletRequest request,
                                         HttpServletResponse response,
                                         Object o, Exception e) {
       /* //开发模式，打印异常信息
        if(Constant.IS_DEVELOP){
            e.printStackTrace();
        }
        //出错的请求路径
        String path = request.getServletPath();
        //记录异常信息
        exceptionService.save(path,e);
        //如果是ajax请求，write json数据
        if(HttpClientUtil.isAjax(request)){
            response.setContentType("application/json;charset=UTF-8");
            PrintWriter writer = null;
            try {
                writer = response.getWriter();
                writer.write(JSON.toJSONString(Result.fail()));
                writer.flush();
                writer.close();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
        if( e instanceof NullPointerException){
            return new ModelAndView("exception/404");
        }
        return new ModelAndView("exception/500");*/
       return null;
    }
}